﻿using SketchUpAPI.NET.Enums;
using SketchUpAPI.NET.SketchUp.Exception;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace SketchUpAPI.NET.Objects
{
    public class Material : Entity
    {
        #region API 函数
        /// <summary>
        /// 创建材质类
        /// </summary>
        /// <param name="material"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUMaterialCreate(out IntPtr material);

        /// <summary>
        /// 获取材质名称
        /// </summary>
        /// <param name="material"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUMaterialGetName(IntPtr material, ref IntPtr name);

        /// <summary>
        /// 获取材质颜色
        /// </summary>
        /// <param name="materialRef"></param>
        /// <param name="color"></param>
        /// <returns></returns>
        [DllImport(LIB)]
        static extern SUResult SUMaterialGetColor(IntPtr material, out Color color);
        #endregion

        /// <summary>
        /// 材质名称
        /// </summary>
        public string Name
        {
            get
            {
                StringRef sr = StringRef.Empty;
                SketchUpExceptionHelper.ThrowSUResult(SUMaterialGetName(Id, ref sr.Id));
                return sr.Dispose();
            }
        }

        /// <summary>
        /// 材质颜色
        /// </summary>
        public Color Color
        {
            get
            {
                SUMaterialGetColor(Id, out Color color);
                return color;
            }
        }

        internal Material(IntPtr id)
        {
            Id = id;
        }

        /// <summary>
        /// 创建一个材质
        /// </summary>
        public Material()
        {
            SketchUpExceptionHelper.ThrowSUResult(SUMaterialCreate(out Id));
        }
    }
}